Here is a complete commented private C code module implementing the Picture function. Use this as a guide for how to create your own functions in UFLs:
/********************************
** UFLSAMP.C
**
** Private C code module
** implementing the Picture UDF.
********************************/
#include <Windows.h>
#include "UFDll.h"
#include "UFMain.h"
#include "UFUser.h"
#define PicturePlaceholder 'x'
/* UDF PROTOTYPE */
ExternC UFError FAR _export PASCAL Picture
(UFParamBlock * ParamBlock);
/*****
* This array gives the program the types for the
* parameters to the UDF, the return
* type, and the name. It also passes the
* address of the actual function code.
*****/
UFFunctionDefStrings FunctionDefStrings [] =
{
{"String Picture (String, String)",
Picture},
{NULL, NULL, NULL}
};
/*****
* The following is the template the program
* will insert into the Formula Editor
* Formula text box when this function is
* selected.
*****/
UFFunctionTemplates FunctionTemplates [] =
{
{"Picture (!,"},
{NULL}
};
/*****
* The following is an example of the format
* for this function. This text will appear
* in the Functions list box of the Formula
* Editor.
*****/
UFFunctionExamples FunctionExamples [] =
{
{"\tPicture (string, picture)"},
{NULL}
};
/*****
* This array contains ASCII string
* representations of the errors which
* could occur.
*****/
char *ErrorTable [] = {
"no error"
};
/* Called for on initialization */
void InitForJob (UFTInt32u jobID)
{
}
/* Called on termination */
void TermForJob (UFTInt32u jobID)
{
}
l/*****
* This function is used by the Picture UDF to
* copy the contents of a source string and a
* format string into a destination string.
*****/
static void copyUsingPicture (char *dest,
const char *source, const char *picture)
{
while (*picture != '\0')
{
If (tolower (*picture) ==
PicturePlaceholder)
If (*source != '\0')
*dest++ = *source++;
Else
; // do not insert anything
Else
*dest++ = *picture;
picture++;
}
// copy the rest of the source
lstrcpy (dest, source);
}
/*****
* This is the User-D efined Function
*****/
ExternC UFError FAR _export PASCAL Picture
(UFParamBlock * ParamBlock)
{
UFParamListElement *FirstParam,*SecondParam;
FirstParam = GetParam (ParamBlock, 1);
SecondParam = GetParam (ParamBlock, 2);
If (FirstParam == NULL || SecondParam ==
NULL)
return UFNotEnoughParameters;
copyUsingPicture (ParamBlock-
ReturnValue.ReturnString,
FirstParam-P arameter.ParamString,
SecondParam-P arameter.ParamString);
return UFNoError;
}
Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |